﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.PmUI.Profile
{
    public partial class AttendenceStatus : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetEmployeeAttendance();
            }
        }
        private void GetEmployeeAttendance()
        {
            AttendanceManager manager = new AttendanceManager();
            List<Attendance> attendances = new List<Attendance>();
            Code code = new Code();
            code.CodeName = Session["Code"].ToString();
            attendances = manager.GetEmployeeAttendanceInfo(code);
            attendanceReportGdv.DataSource = attendances;
            attendanceReportGdv.DataBind();
            if (attendances.Count > 0)
            {

                lblEmpCode.Text = "Employee Code: " + code.CodeName;
            }
            else
            {
                lblEmpCode.ForeColor = Color.Red;
                lblEmpCode.Text = "Employee Code: " + code.CodeName + " has no Attendance Report";
            }
        }

        protected void attendanceReportGdv_RowEditing(object sender, GridViewEditEventArgs e)
        {
            attendanceReportGdv.EditIndex = e.NewEditIndex;
            GetEmployeeAttendance();

        }

        protected void attendanceReportGdv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            attendanceReportGdv.EditIndex = -1;
            GetEmployeeAttendance();
        }

        protected void attendanceReportGdv_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridView gv = (GridView)sender;
            GridViewRow row = gv.Rows[e.RowIndex];
            int id = Convert.ToInt32(((Label)attendanceReportGdv.Rows[e.RowIndex].FindControl("lblId")).Text);
            TextBox txtComments = (TextBox)row.FindControl("txtComment");
            string comments = txtComments.Text;

            AttendanceManager manager = new AttendanceManager();
            if (manager.AddComment(id, comments))
            {
                lblCommentMsg.ForeColor = Color.Green;
                lblCommentMsg.Text = "Comments Updated Successfully";
                attendanceReportGdv.EditIndex = -1;
                GetEmployeeAttendance();
            }
        }
    }
}